<?php
/**
 * Created by PhpStorm.
 * User: ruma
 * Date: 2019/1/18
 * Time: 12:15
 */

namespace app\admin\validate;


use app\Excepiton\BaseException;
use app\Excepiton\ParameterException;
use think\Request;
use think\Validate;
use think\Controller;

class BaseValidate extends Validate
{
    /**
     *全局验证器的封装方法
     *
     * @return $data 验证成功返回post数组
     */
    public function postCheckAndGet(){
        $request = Request::instance();
        //1.判断是否传入post参数,防止view页面的正常显示.
        if ($request->isPost()){
            //2.获取传入的post参数
            $data = $request->post();
            //3.参数校验(多验证方法的批量)
            $result = $this->batch()->check($data);
            //4.返回结果
            if (!$result){
//                $array = ['postError' => 'string'];
//                return array_merge($array , $this->error);
                throw new ParameterException([
                    'msg' => $this->error
                ]);
            }
            return $data;
        }
    }
}